<?php 

    $canon_options_post = get_option('canon_options_post');

    $last_alignment = "right";
    $default_excerpt_length = 450;


?>



                		
                        <!-- MAIN LOOP -->
                        <?php while ( have_posts() ) : the_post(); ?>

                        <?php 

                            $post_format = get_post_format();
                            $result_cmb_alignment = get_post_meta(get_the_ID(), 'cmb_alignment', true);
                            $result_cmb_excerpt = get_post_meta(get_the_ID(), 'cmb_excerpt', true);
                            $result_cmb_media_link = get_post_meta(get_the_ID(), 'cmb_media_link', true);
                            $result_cmb_use_media_link = get_post_meta(get_the_ID(), 'cmb_use_media_link', true);
                            $result_cmb_quote_is_tweet = get_post_meta($post->ID, 'cmb_quote_is_tweet', true);

                        ?>

                            <?php 

                                //LEFT ALIGN
                                if (        (($post_format === false) && ($result_cmb_alignment == "left") && (has_post_thumbnail(get_the_ID()))) ||
                                            (($post_format === false) && ($result_cmb_alignment == "") && (has_post_thumbnail(get_the_ID())) && ($last_alignment == "right")) ) {

                                    $last_alignment = "left";

                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <div class="third">
                                            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                            <div class="meta clearfix"> 
                                                <h6 class="date"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                                <h6 class="tags"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                            </div>
                                            <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                            <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Read More','loc_canon'); ?></a></p>
                                        </div>
                                        
                                        <?php 
                                            if (!empty($result_cmb_use_media_link) && !empty($result_cmb_media_link)) {
                                                echo ' <div class="two-thirds last">';
                                                echo $result_cmb_media_link;        
                                                echo '</div>';
                                            } elseif ( (has_post_thumbnail(get_the_ID())) && get_post(get_post_thumbnail_id(get_the_ID())) ) {
                                                echo ' <div class="mosaic-block fade feat_mosaic_inline two-thirds last">';
                                                $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');
                                                $img_alt = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true);
                                                $img_post = get_post(get_post_thumbnail_id(get_the_ID()));
                                                printf('<a href="%s" class="mosaic-overlay fancybox" data-fancybox-group="gallery" title="%s"></a>', esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title));
                                                printf('<div class="mosaic-backdrop"><img src="%s" alt="%s" /></div>', esc_url($post_thumbnail_src[0]), esc_attr($img_alt));
                                                echo '</div>';
                                            }
                                        ?>
                                        
                                    </div>

                                    <hr/>
                                <?php    
                                }

                                //RIGHT ALIGN
                                elseif (    ( ($post_format === false) && ($result_cmb_alignment == "right") && (has_post_thumbnail(get_the_ID())) ) ||
                                            ( ($post_format === false) && ($result_cmb_alignment == "") && (has_post_thumbnail(get_the_ID())) && ($last_alignment == "left")) ) {
                                    
                                    $last_alignment = "right";

                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <div class="third last right">
                                            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                            <div class="meta clearfix"> 
                                                <h6 class="date"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                                <h6 class="tags"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                            </div>
                                            <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                            <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Read More','loc_canon'); ?></a></p>
                                        </div>
                                        
                                        <?php 
                                            if (!empty($result_cmb_use_media_link) && !empty($result_cmb_media_link)) {
                                                echo ' <div class="two-thirds">';
                                                echo $result_cmb_media_link;        
                                                echo '</div>';
                                            } elseif ( (has_post_thumbnail(get_the_ID())) && get_post(get_post_thumbnail_id(get_the_ID())) ) {
                                                echo ' <div class="mosaic-block fade feat_mosaic_inline two-thirds">';
                                                $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');
                                                $img_alt = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true);
                                                $img_post = get_post(get_post_thumbnail_id(get_the_ID()));
                                                printf('<a href="%s" class="mosaic-overlay fancybox" data-fancybox-group="gallery" title="%s"></a>', esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title));
                                                printf('<div class="mosaic-backdrop"><img src="%s" alt="%s" /></div>', esc_url($post_thumbnail_src[0]), esc_attr($img_alt));
                                                echo '</div>';
                                            }
                                        ?>

                                    </div> 

                                    <hr/>
                                <?php
                                }

                                //QUOTE
                                if (($post_format == "quote") && ($result_cmb_quote_is_tweet != "checked")) {
                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <div class="quote">
                                            <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                            <div class="meta clearfix"> 
                                                <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                                <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                            </div>
                                        </div>
                                    </div>

                                    <hr/>

                                <?php
                                }

                                //TWEET
                                if (($post_format == "quote") && ($result_cmb_quote_is_tweet == "checked")) {
                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <div class="tweet">
                                            <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                            <div class="meta clearfix"> 
                                                <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                                <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                            </div>
                                        </div>
                                    </div>

                                    <hr/>

                                <?php
                                }

                                //VIDEO POST
                                if ($post_format == "video") {
                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                        <div class="meta clearfix"> 
                                            <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                            <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                        </div>
                                        <?php 
                                            if (!empty($result_cmb_use_media_link) && !empty($result_cmb_media_link)) {
                                                echo $result_cmb_media_link;        
                                            } else {
                                                echo ' <div class="mosaic-block fade feat_mosaic">';
                                                $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');
                                                $img_alt = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true);
                                                $img_post = get_post(get_post_thumbnail_id(get_the_ID()));
                                                printf('<a href="%s" class="mosaic-overlay fancybox" data-fancybox-group="gallery" title="%s"></a>', esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title));
                                                printf('<div class="mosaic-backdrop"><img src="%s" alt="%s" /></div>', esc_url($post_thumbnail_src[0]), esc_attr($img_alt));
                                                echo '</div>';
                                            }
                                        ?>

                                        <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                        <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Read More','loc_canon'); ?></a></p>
              
                                    </div>
                                    
                                    <hr/>
                        
                                <?php
                                }

                                //AUDIO POST
                                if ($post_format == "audio") {

                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                        <div class="meta clearfix"> 
                                            <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                            <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                        </div>
                                        <?php 
                                            if (!empty($result_cmb_use_media_link) && !empty($result_cmb_media_link)) {
                                                echo do_shortcode($result_cmb_media_link); 
                                            } else {
                                                echo ' <div class="mosaic-block fade feat_mosaic">';
                                                $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');
                                                $img_alt = get_post_meta(get_post_thumbnail_id(get_the_ID()), '_wp_attachment_image_alt', true);
                                                $img_post = get_post(get_post_thumbnail_id(get_the_ID()));
                                                printf('<a href="%s" class="mosaic-overlay fancybox" data-fancybox-group="gallery" title="%s"></a>', esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title));
                                                printf('<div class="mosaic-backdrop"><img src="%s" alt="%s" /></div>', esc_url($post_thumbnail_src[0]), esc_attr($img_alt));
                                                echo '</div>';
                                            }
                                        ?>

                                        <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                            
                                        <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Read More','loc_canon'); ?></a></p>
              
                                    </div>
                                    
                                    <hr/>
                        
                                <?php
                                }

                                //GALLERY POST
                                if ($post_format == "gallery") {

                                    $args = array(
                                        'post_type' => 'attachment',
                                        'numberposts' => -1,
                                        'post_status' => null,
                                        'post_parent' => get_the_ID()
                                    );

                                    $project_attachments = get_posts( $args );
                                    //var_dump($project_attachments);

                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                        <div class="meta clearfix"> 
                                            <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                            <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                        </div>
                                            
                                        <div class="flexslider gallery-post-type">
                                            <ul class="slides">
                                                <?php 
                                                if ( has_post_thumbnail(get_the_ID()) && get_post(get_post_thumbnail_id(get_the_ID())) ) {
                                                    $post_thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()),'full');
                                                    $img_post = get_post(get_post_thumbnail_id(get_the_ID()));
                                                    printf("<li><a href='%s' title='%s'><img src='%s'></a></li>", esc_url($post_thumbnail_src[0]), esc_attr($img_post->post_title), esc_url($post_thumbnail_src[0])); 
                                                }

                                                ?>

                                                <?php 
                                                for ($i = 0; $i < count($project_attachments); $i++) {
                                                    if (get_post_thumbnail_id(get_the_ID()) != $project_attachments[$i]->ID) {
                                                        $attachment_src = wp_get_attachment_image_src($project_attachments[$i]->ID, 'full');
                                                        $img_post = get_post($project_attachments[$i]->ID);
                                                        printf("<li><a href='%s' title='%s'><img src='%s'></a></li>", esc_url($attachment_src[0]), esc_attr($img_post->post_title), esc_url($attachment_src[0])); 
                                                    }
                                                }
                                                ?>

                                            </ul>
                                        </div>

                                        <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                        <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Read More','loc_canon'); ?></a></p>
              

                                    </div>
                                    
                                    <hr/>
                        
                                <?php
                                }

                                //NO FEAT IMAGE POST
                                if (($post_format === false) && (!has_post_thumbnail(get_the_ID()))) {
                                ?>
                                    <div <?php post_class("clearfix"); ?>>
                                        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                        <div class="meta clearfix"> 
                                            <h6 class="date left"><?php _e('Posted on','loc_canon'); ?> <?php echo mb_localize_datetime(get_the_time(get_option('date_format'))); ?></h6>
                                            <h6 class="tags right"><?php if ($canon_options_post['show_tags'] == "checked") the_tags("",""); ?></h6>
                                        </div>
                                        <p><?php if (empty($result_cmb_excerpt)) { echo mb_make_excerpt(get_the_content(), $default_excerpt_length, true); } else {echo do_shortcode($result_cmb_excerpt);} ?></p>
                                        <p><a href="<?php the_permalink(); ?>" class="more"><?php _e('Read More','loc_canon'); ?></a></p>
                                    </div>
                                    
                                    
                                    <hr/>
                                <?php
                                }


                            ?>

                        <?php endwhile; ?>
                        <!-- END LOOP -->

                        <!-- PAGINATION -->
                        <?php get_template_part("inc/templates/template_paginate_links"); ?>

                    
                    <!-- Finish Main Content -->
                    </div>    
                </div>
                

            </div> <!-- #main -->
        </div> <!-- #main-container -->
